import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;

public class ClientSockerTest {
    public static void main(String[] args){
        Socket socket = null;
        PrintStream printStream = null;
        try {
            //1.创建Socket类型的对象并提供服务器的主机名和端口号
            socket = new Socket("127.0.0.1", 3000);
            for (int i = 0; i < 2; i++) {
                ClientSocketThread thread = new ClientSocketThread(socket);
                thread.start();
                System.out.println( thread.getId() + "连接服务器成功！");
            }
            for (;;) {}
        } catch(Exception e){
            e.printStackTrace();
        } finally {
            System.out.println("----------------------------------------Client端停止执行-------------------------------------------------");
            //关闭 Socket 并释放相关的资源
            if(null != printStream){
                printStream.close();
            }
            if(null != socket){
                try {
                    socket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
